package types

import "github.com/shopspring/decimal"

type EpisodeItem struct {
	ProjectId       uint64   `json:"project_id"`
	EpisodeCodeList []string `json:"episode_code_list"`
}
type PlanEpisodeItem struct {
	ProjectId      uint64 `json:"project_id"`
	EpisodeCodeStr string `json:"episode_code_str"`
}
type FinanceHourCountReq struct {
	TaskType      string        `json:"task_type" binding:"required"`
	Month         string        `json:"month" binding:"required"`
	EpisodeList   []EpisodeItem `json:"episode_list"`
	ProjectIdList []uint64      `json:"project_id_list"`
}
type FinanceHourCountResItem struct {
	ProjectID           uint64  `json:"project_id"`
	InitialEpisodeCode  string  `json:"initial_episode_code"`
	Hours               float64 `json:"hours"`
	UserID              uint64  `json:"user_id"`
	ID                  uint64  `json:"id"`
	Type                string  `json:"type"`
	Name                string  `json:"name"`
	ProjectName         string  `json:"project_name"`
	ParentID            uint64  `json:"parent_id"`
	Percent             float64 `json:"percent"`
	DepartmentHour      float64 `json:"department_hour"`
	HoursTotal          float64 `json:"hours_total"`
	DepartmentHourTotal float64 `json:"department_hour_total"`
}

type DepartmentUserDingManhourM struct {
	DepartmentId uint64  `json:"department_id"`
	UserId       uint64  `json:"user_id"`
	ManHourM     float64 `json:"man_hour_m"`
}

type DepartmentUserDingManhour struct {
	WorkDate       uint64          `json:"work_date"`
	StepCategoryId uint64          `json:"step_category_id"`
	UserId         uint64          `json:"user_id"`
	Hours          float64         `json:"hours"`
	HoursDecimal   decimal.Decimal `json:"hours_decimal"`
	Grade          string          `json:"grade"`
	GroupName      string          `json:"group_name"`
	DepartmentName string          `json:"department_name"`
	UserName       string          `json:"user_name"`
}

type FinanceAssetHourCountReq struct {
	ProjectId uint64 `json:"project_id"`
}

type FinanceAssetHourCountResItem struct {
	ProjectName          string   `json:"project_name"`
	AssetName            string   `json:"asset_name"`
	AssetEpisodeCode     string   `json:"asset_episode_code"`
	AssetGrade           string   `json:"asset_grade"`
	DepartmentParentName string   `json:"department_parent_name"`
	DepartmentName       string   `json:"department_name"`
	UserName             string   `json:"user_name"`
	DingHours            float64  `json:"ding_hours"`
	RelatedEpisodeList   []string `json:"related_episode_list"`
	EpisodeCost          float64  `json:"episode_cost"`
}

// PlanEpisodeStepCategoryItem 计划筛选出来的项目的各环节应完成的集
type PlanEpisodeStepCategoryItem struct {
	ProjectId      uint64 `json:"project_id"`
	EpisodeCodeStr string `json:"episode_code_str"`
	StepCategoryId uint64 `json:"step_category_id"`
}

type EntityDepartmentStepCategoryHourCount struct {
	ProjectId          uint64          `json:"project_id"`
	InitialEpisodeCode string          `json:"initial_episode_code"`
	EntityName         string          `json:"entity_name"`
	Grade              string          `json:"grade"`
	EntityId           uint64          `json:"entity_id"`
	StepCategoryId     uint64          `json:"step_category_id"`
	DepartmentId       uint64          `json:"department_id"`
	Hours              float64         `json:"hours"`
	HoursDecimal       decimal.Decimal `json:"hours_decimal"`
}

type EntityDepartmentHourCount struct {
	ProjectId          uint64          `json:"project_id"`
	StepCategoryId     uint64          `json:"step_category_id"`
	ProjectName        string          `json:"project_name"`
	InitialEpisodeCode string          `json:"initial_episode_code"`
	EntityName         string          `json:"entity_name"`
	Grade              string          `json:"grade"`
	EntityId           uint64          `json:"entity_id"`
	DepartmentId       uint64          `json:"department_id"`
	Hours              float64         `json:"hours"`
	HoursDecimal       decimal.Decimal `json:"hours_decimal"`
	Proportion         decimal.Decimal
	RelatedEpisodeList []string
}

type EntityDepartmentHourCountList []EntityDepartmentHourCount

var gradeRank = map[string]uint64{"S": 100, "A": 70, "B": 50, "C": 30}

// Len 计算长度
func (entityDepartmentHourCountList EntityDepartmentHourCountList) Len() int {
	return len(entityDepartmentHourCountList)
}

// Less 比对大小
func (entityDepartmentHourCountList EntityDepartmentHourCountList) Less(i, j int) bool {
	return gradeRank[entityDepartmentHourCountList[i].Grade] > gradeRank[entityDepartmentHourCountList[j].Grade] ||
		(gradeRank[entityDepartmentHourCountList[i].Grade] == gradeRank[entityDepartmentHourCountList[j].Grade] && entityDepartmentHourCountList[i].EntityName > entityDepartmentHourCountList[j].EntityName) ||
		(gradeRank[entityDepartmentHourCountList[i].Grade] == gradeRank[entityDepartmentHourCountList[j].Grade] && entityDepartmentHourCountList[i].EntityName == entityDepartmentHourCountList[j].EntityName && entityDepartmentHourCountList[i].DepartmentId < entityDepartmentHourCountList[j].DepartmentId)
}

// Swap 交换位置
func (entityDepartmentHourCountList EntityDepartmentHourCountList) Swap(i, j int) {
	entityDepartmentHourCountList[i], entityDepartmentHourCountList[j] = entityDepartmentHourCountList[j], entityDepartmentHourCountList[i]
}

type EpisodeCodeStepCategoryPlanItem struct {
	EpisodeCode    string `json:"episode_code"`
	StepCategoryId uint64 `json:"step_category_id"`
	StartTime      uint64 `json:"start_time"`
	EndTime        uint64 `json:"end_time"`
}
type AssetRelatedEpisodeList struct {
	EntityId       uint64 `json:"entity_id"`
	EpisodeCodeStr string `json:"episode_code_str"`
}
type AssetRelatedEpisodeListRes map[uint64]AssetRelatedEpisodeList

type FinanceAssetHourCountRes []FinanceAssetHourCountResItem

// Len 计算长度
func (fahcr FinanceAssetHourCountRes) Len() int {
	return len(fahcr)
}

// Less 比对大小
func (fahcr FinanceAssetHourCountRes) Less(i, j int) bool {
	return fahcr[i].AssetName > fahcr[j].AssetName ||
		(fahcr[i].AssetName == fahcr[j].AssetName && fahcr[i].DepartmentParentName > fahcr[j].DepartmentParentName) ||
		(fahcr[i].AssetName == fahcr[j].AssetName && fahcr[i].DepartmentParentName == fahcr[j].DepartmentParentName && fahcr[i].DepartmentName < fahcr[j].DepartmentName)
}

// Swap 交换位置
func (fahcr FinanceAssetHourCountRes) Swap(i, j int) {
	fahcr[i], fahcr[j] = fahcr[j], fahcr[i]
}

type EntityDepartmentStepCategoryHourCountV3 struct {
	ProjectId          uint64          `json:"project_id"`
	InitialEpisodeCode string          `json:"initial_episode_code"`
	EntityName         string          `json:"entity_name"`
	Grade              string          `json:"grade"`
	EntityId           uint64          `json:"entity_id"`
	StepCategoryId     uint64          `json:"step_category_id"`
	DepartmentId       uint64          `json:"department_id"`
	UserId             uint64          `json:"user_id"`
	Hours              float64         `json:"hours"`
	HoursDecimal       decimal.Decimal `json:"hours_decimal"`
}

type EntityDepartmentHourCountV3 struct {
	ProjectId          uint64          `json:"project_id"`
	StepCategoryId     uint64          `json:"step_category_id"`
	ProjectName        string          `json:"project_name"`
	InitialEpisodeCode string          `json:"initial_episode_code"`
	EntityName         string          `json:"entity_name"`
	Grade              string          `json:"grade"`
	EntityId           uint64          `json:"entity_id"`
	DepartmentId       uint64          `json:"department_id"`
	Hours              float64         `json:"hours"`
	HoursDecimal       decimal.Decimal `json:"hours_decimal"`
	Proportion         decimal.Decimal
	RelatedEpisodeList []string
	UserId             uint64 `json:"user_id"`
}
type EntityDepartmentHourCountListV3 []EntityDepartmentHourCountV3

// Len 计算长度
func (entityDepartmentHourCountList EntityDepartmentHourCountListV3) Len() int {
	return len(entityDepartmentHourCountList)
}

// Less 比对大小
func (entityDepartmentHourCountList EntityDepartmentHourCountListV3) Less(i, j int) bool {
	return gradeRank[entityDepartmentHourCountList[i].Grade] > gradeRank[entityDepartmentHourCountList[j].Grade] ||
		(gradeRank[entityDepartmentHourCountList[i].Grade] == gradeRank[entityDepartmentHourCountList[j].Grade] && entityDepartmentHourCountList[i].EntityName > entityDepartmentHourCountList[j].EntityName) ||
		(gradeRank[entityDepartmentHourCountList[i].Grade] == gradeRank[entityDepartmentHourCountList[j].Grade] && entityDepartmentHourCountList[i].EntityName == entityDepartmentHourCountList[j].EntityName && entityDepartmentHourCountList[i].DepartmentId < entityDepartmentHourCountList[j].DepartmentId)
}

// Swap 交换位置
func (entityDepartmentHourCountList EntityDepartmentHourCountListV3) Swap(i, j int) {
	entityDepartmentHourCountList[i], entityDepartmentHourCountList[j] = entityDepartmentHourCountList[j], entityDepartmentHourCountList[i]
}

type FinanceAssetHourCountResItemV3 struct {
	ProjectName          string   `json:"project_name"`
	AssetName            string   `json:"asset_name"`
	AssetEpisodeCode     string   `json:"asset_episode_code"`
	AssetGrade           string   `json:"asset_grade"`
	DepartmentParentName string   `json:"department_parent_name"`
	DepartmentName       string   `json:"department_name"`
	UserName             string   `json:"user_name"`
	DingHours            float64  `json:"ding_hours"`
	RelatedEpisodeList   []string `json:"related_episode_list"`
	EpisodeCost          float64  `json:"episode_cost"`
	WorkHour             float64  `json:"work_hour"`
}

type FinanceAssetHourCountResV3 []FinanceAssetHourCountResItemV3

// Len 计算长度
func (fahcr FinanceAssetHourCountResV3) Len() int {
	return len(fahcr)
}

// Less 比对大小
func (fahcr FinanceAssetHourCountResV3) Less(i, j int) bool {
	return fahcr[i].AssetName > fahcr[j].AssetName ||
		(fahcr[i].AssetName == fahcr[j].AssetName && fahcr[i].DepartmentParentName > fahcr[j].DepartmentParentName) ||
		(fahcr[i].AssetName == fahcr[j].AssetName && fahcr[i].DepartmentParentName == fahcr[j].DepartmentParentName && fahcr[i].DepartmentName < fahcr[j].DepartmentName)
}

// Swap 交换位置
func (fahcr FinanceAssetHourCountResV3) Swap(i, j int) {
	fahcr[i], fahcr[j] = fahcr[j], fahcr[i]
}
